package distinctAverages;

import java.util.*;

public class Solution {
    public int distinctAverages(int[] nums) {
        Set<Double> set = new HashSet<>();
        LinkedList<Integer> list = new LinkedList<>();
        Arrays.sort(nums);
        for (int i = 0; i < nums.length; i++) {
            list.add(nums[i]);
        }
        return f(list,set);
    }
    private int f (LinkedList<Integer> list,Set<Double> set) {
        if(list.isEmpty()) {
            return set.size();
        }
        int min = list.removeFirst();
        int max = list.removeLast();
        set.add((max + min)*1.0/2);
        return f(list,set);
    }
}
